package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.SupplierCriteria;
import com.leo.ibatis.demo.dao.SupplierDao;
import com.leo.ibatis.demo.domain.Supplier;
import com.leo.ibatis.demo.service.SupplierService;

public class SupplierServiceImpl extends Service implements SupplierService {

	private SupplierDao supplierDao;

	public void setSupplierDao(SupplierDao supplierDao) {
		this.supplierDao = supplierDao;
	}

	public void insert(Supplier supplier) {
		supplierDao.insert(supplier);
	}

	public int update(Supplier supplier) {
		int actualRowsAffected = 0;
		
		int suppid = supplier.getSuppid();

		Supplier _oldSupplier = supplierDao.select(suppid);
		
		if (_oldSupplier != null) {
			actualRowsAffected = supplierDao.update(supplier);
		}
		
		return actualRowsAffected;
	}

	public int delete(int suppid) {
		int actualRowsAffected = 0;
		
		Supplier _oldSupplier = supplierDao.select(suppid);
		
		if (_oldSupplier != null) {
			actualRowsAffected = supplierDao.delete(suppid);
		}
		
		return actualRowsAffected;
	}
	
	public Supplier select(int suppid) {
		return supplierDao.select(suppid);
	}

	public List<Supplier> list(SupplierCriteria supplierCriteria) {
		return supplierDao.list(supplierCriteria);
	}
	
	public List<Supplier> listOnPage(SupplierCriteria supplierCriteria) {
		return supplierDao.listOnPage(supplierCriteria);
	}

}
